# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/montana_defconfig

pkgname=linux-motorola-montana
pkgver=3.18.140
pkgrel=0
pkgdesc="Motorola Moto G5s kernel fork"
arch="aarch64"
_carch="arm64"
_flavor="motorola-montana"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev devicepkg-dev dtbtool xz"

# Source
_repository="android_kernel_motorola_msm8937"
_commit="1e8993177823e4ddf3b5d91da6335d75ad513dec"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/MontanaDevelopment/$_repository/archive/$_commit.tar.gz
	$_config
	gcc10-extern_YYLOC_global_declaration.patch
"
builddir="$srcdir/$_repository-$_commit"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"

	# Generate master DTB (deviceinfo_bootimg_qcdt)
	dtbTool -s 2048 -p "scripts/dtc/" -o "arch/arm/boot/dt.img" "arch/arm/boot/"
}

package() {
	KERNEL_IMAGE_NAME="Image.gz" downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor"
}

sha512sums="369dfffb8088958226b1a259705f4af1e5e9b02d32fde4cd9f9c50f2165658a187f5aa74badff77761a02c2c088484789267db6afbcc3e802dd62b1e819553c0  linux-motorola-montana-1e8993177823e4ddf3b5d91da6335d75ad513dec.tar.gz
3d05f43f3c3ca5afc5bc46aeb7b08ffda78ca6b146bf9d8969c14da3b62ae9fa83dab85cac291aadf9ee4d182e98d6d56f8da9324681a6b697e22456c9fbbee5  config-motorola-montana.aarch64
2b48f1bf0e3f70703d2cdafc47d5e615cc7c56c70bec56b2e3297d3fa4a7a1321d649a8679614553dde8fe52ff1051dae38d5990e3744c9ca986d92187dcdbeb  gcc10-extern_YYLOC_global_declaration.patch"
